﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NIIT.SaoBacDau.Aupi.HospitalManagement.Entities;
using NIIT.SaoBacDau.Aupi.HospitalManagement.Languages;

namespace NIIT.SaoBacDau.Aupi.HospitalManagement
{
    
    public partial class Managements : Form
    {
        public Boolean bln_RememberPassword { get; set; }
        public enum Option { Add, Edit }
        Obj_Employee em = new Obj_Employee();
        #region Phần form quản lý bệnh viện
        public Managements()
        {
            InitializeComponent();
        }

        private void Managements_Load(object sender, EventArgs e)
        {
            ShowAddPatient(8);
        }

        public Managements(Entities.Obj_Employee emp, Boolean RememberPassWord)
        {
            InitializeComponent();
            em = emp;
            bln_RememberPassword = RememberPassWord;
        }

        private void Managements_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult DR = MessageBox.Show("Are you sure exit hospital management ?", "Exit Application", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (DR == DialogResult.Yes)
            {
                e.Cancel = false;
                Application.ExitThread();
            }
            else
                e.Cancel = true;
        }

        #endregion

        #region Phần sự kiện trên form 
        private void tsb_MedicalHistory_Click(object sender, EventArgs e)
        {
            ShowPatient(3, 3);
        }

        private void tsb_AddPatient_Click(object sender, EventArgs e)
        {
            if (scn_ManagementSystem.Panel2.Controls.Count == 0)
                ShowAddPatient(0);
            else
                ShowAddPatient(0);
        }

        private void tsb_EditPatient_Click(object sender, EventArgs e)
        {
            ShowPatient(1,1);
        }

        private void tsb_SearchPatient_Click(object sender, EventArgs e)
        {
            ShowPatient(2,2);
        }

        private void tsb_PatientPayment_Click(object sender, EventArgs e)
        {
            ShowPatient(4, 4);
        } 
        #endregion

        #region Phần phương thức xử lý

        public void ShowAddPatient(int element)
        {
            DisableControl(element);
            this.scn_ManagementSystem.Panel2.Controls.Clear();
            AddPatient ap = new AddPatient(Option.Add, 0);
            ap.Parent = this.scn_ManagementSystem.Panel2;
            ap.Show();
        }

        private void DisableControl(int element)
        {
            tsb_AddPatient.Enabled = false;
            tsb_EditPatient.Enabled = false;
            tsb_SearchPatient.Enabled = false;
            tsb_MedicalHistory.Enabled = false;
            tsb_PatientPayment.Enabled = false;
            tsb_ReportRecepPatient.Enabled = false;
            tsb_StatisticPatient.Enabled = false;
            tsb_Papers.Enabled = false;
            switch(element)
            {
                case 0:
                    tsb_AddPatient.Enabled = true;
                    break;
                case 1:
                    tsb_EditPatient.Enabled = true;
                    break;
                case 2:
                    tsb_SearchPatient.Enabled = true;
                    break;
                case 3:
                    tsb_MedicalHistory.Enabled =true;
                    break;
                case 4:
                    tsb_PatientPayment.Enabled = true;
                    break;
                case 5:
                    tsb_ReportRecepPatient.Enabled = true;
                    break;
                case 6:
                    tsb_StatisticPatient.Enabled = true;
                    break;
                case 7:
                    tsb_Papers.Enabled = true;
                    break;
                default:
                    tsb_AddPatient.Enabled = true;
                    tsb_EditPatient.Enabled = true;
                    tsb_SearchPatient.Enabled = true;
                    tsb_MedicalHistory.Enabled = true;
                    tsb_PatientPayment.Enabled = true;
                    tsb_ReportRecepPatient.Enabled = true;
                    tsb_StatisticPatient.Enabled = true;
                    tsb_Papers.Enabled = true;
                    break;
            }
            
        }

        public void ShowPatient(int element,int type)
        {
            DisableControl(element);
            this.scn_ManagementSystem.Panel2.Controls.Clear();
            ListPatient lp = new ListPatient(type);
            lp.Parent = this.scn_ManagementSystem.Panel2;
            lp.Show();
        }      

        public void EditPatient(int patientID)
        {
            this.scn_ManagementSystem.Panel2.Controls.Clear();
            AddPatient ap = new AddPatient(Managements.Option.Edit, patientID);
            ap.Parent = this.scn_ManagementSystem.Panel2;
            ap.Show();
        }

        public void ShowHistoryOrPayment(int p, Obj_Patient patient)
        {
            DisableControl(p);
            this.scn_ManagementSystem.Panel2.Controls.Clear();
            if (p == 3)
            {
                MedicalHistory mh = new MedicalHistory();
                mh.Parent = this.scn_ManagementSystem.Panel2;
                mh.Show();
            }
            else if (p == 4)
            {
                PatientPayment pp = new PatientPayment();
                pp.Parent = this.scn_ManagementSystem.Panel2;
                pp.Show();
            }
        }
        #endregion  
    }
}
